package com.times.exception;

import com.gitee.sop.servercommon.exception.ExceptionHolder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName exception
 * @Description TODO
 * @Author zyy
 * @Date 2022/8/16 11:37
 * @Version 1.0
 **/
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {

        // 在返回前加这一句
        ExceptionHolder.hold(request, response, exception);

        // 下面可以实现自己的全局异常处理
        return new Object();
    }
}
